import { defineStore } from 'pinia'
import { default as $http } from '@/utils/http'

export const useMapStore = defineStore('map', {
  state: () => {
    return {
      // 地图全屏状态
      isMapFullScreen: false,
      // 地图初始化数据请求状态
      isMapInitDataRequest: false,
      // 采集点数量
      mapCollectionPointNum: [],
      // 采集点坐标
      mapCollectionPointLngLat: [],
      // 常住人口
      mapPermanentPopulation: [],
      // 核酸采集量
      mapNACollectionAmount: [],
      // 监控数量
      mapMonitorQuantity: [],
    }
  },
  actions: {
    // 地图全屏状态改变
    mapFullScreenChange(state) {
      this.isMapFullScreen = state
    },
    // 获取地图初始化数据
    getMapInitData() {
      if (this.isMapInitDataRequest) return

      this.getMapCollectionPointNum()
      this.getMapCollectionPointLngLat()
      this.isMapInitDataRequest = false
    },
    // 获取采集点数量
    getMapCollectionPointNum() {
      $http.get('/screen/town/village').then(res => {
        const { data = [] } = res || {}

        this.mapCollectionPointNum = data || []
      })
    },
    // 获取采集点坐标
    getMapCollectionPointLngLat() {
      $http.get('/screen/district/village').then(res => {
        const { data = [] } = res || {}

        this.mapCollectionPointLngLat = data || []
      })
    },
  },
})
